package com.edu.web.controller.info;

import com.edu.common.annotation.Log;
import com.edu.common.core.controller.BaseController;
import com.edu.common.core.domain.AjaxResult;
import com.edu.common.enums.BusinessType;
import com.edu.common.utils.poi.ExcelUtil;
import com.edu.system.domain.TExamMiss;
import com.edu.system.domain.dto.ChargeStatDTO;
import com.edu.system.domain.dto.ClassCardPayDTO;
import com.edu.system.domain.dto.StatisticsExamDTO;
import com.edu.system.domain.req.StatisticsCardUsedReq;
import com.edu.system.service.ITCardService;
import com.edu.system.service.ITChargeRecordService;
import com.edu.system.service.ITExamMissService;
import com.edu.system.service.ITExaminationService;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 *
 * @author xxxx
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/system/statistics")
public class StatisticsController extends BaseController {


  @Resource
  private ITExamMissService itExamMissService;
  @Resource
  private ITExaminationService itExaminationService;
  @Resource
  private ITChargeRecordService itChargeRecordService;
  @Resource
  private ITCardService itCardService;


  /**
   * 考试统计
   * @param miss
   * @return
   */
  @PreAuthorize("@ss.hasPermi('system:statistics:exam')")
  @GetMapping("/exam/stat")
  public AjaxResult stat(TExamMiss miss) {
    StatisticsExamDTO dto = itExaminationService.examStat(miss.getCohort(), miss.getExamId(), miss.getLessonName());

    return AjaxResult.success(dto);
  }

  /**
   * 刷卡人数统计
   * @return
   */
  @PreAuthorize("@ss.hasPermi('system:statistics:canteen')")
  @GetMapping("/canteen/stat")
  public AjaxResult canteenStat() {
    return AjaxResult.success(itChargeRecordService.getCountInfo());
  }

  /**
   * 食堂余额统计
   * @return
   */
  @PreAuthorize("@ss.hasPermi('system:statistics:canteen')")
  @GetMapping("/canteen/balance/{balance}")
  public AjaxResult canteenBalance(@PathVariable("balance") Integer balance) {
    return AjaxResult.success(itCardService.cntBalance(balance));
  }

  /**
   * 各班级刷卡数列表
   * @return
   */
  @PreAuthorize("@ss.hasPermi('system:statistics:canteen')")
  @GetMapping("/card/usedList")
  public AjaxResult cardUsedList(StatisticsCardUsedReq req) {

    // todo
    return AjaxResult.success(new ClassCardPayDTO());
  }

  /**
   * 导出班级刷卡统计
   */
  @PreAuthorize("@ss.hasPermi('system:statistics:canteen')")
  @Log(title = "导出班级刷卡统计", businessType = BusinessType.EXPORT)
  @PostMapping("/exportCanteen")
  public void exportCanteen(HttpServletResponse response, StatisticsCardUsedReq req) {
    List<ClassCardPayDTO> list = null;
    ExcelUtil<ClassCardPayDTO> util = new ExcelUtil<ClassCardPayDTO>(ClassCardPayDTO.class);
    util.exportExcel(response, list, "数据");
  }




}
